package com.cn.longdistancebusstation.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.cn.longdistancebusstation.R;
import com.cn.longdistancebusstation.enumxx.PassengerType;
import com.cn.longdistancebusstation.model.Contacter;

import java.util.ArrayList;

/**
 * Created by mucheng on 2018/1/26.
 */

public class LinkmanAdapter extends BaseAdapter{
    private Context ctx;
    private ArrayList<Contacter> list;
    public LinkmanAdapter(Context ctx,ArrayList<Contacter> list){
        this.ctx=ctx;
        this.list=list;

    }
    @Override
    public int getCount() {
        return list.size();
    }

    @Override
    public Object getItem(int position) {
        return list.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder=null;
        if(convertView==null){
            holder=new ViewHolder();
            convertView= LayoutInflater.from(ctx).inflate(R.layout.view_linkman,null);
            holder.linkman_name=(TextView)convertView.findViewById(R.id.linkman_name);
            holder.linkman_type=(TextView)convertView.findViewById(R.id.linkman_type);
            holder.linkman_idcard_number=(TextView)convertView.findViewById(R.id.linkman_idcardnumber);
            convertView.setTag(holder);
        }else{
            holder=(ViewHolder)convertView.getTag();
        }
        Contacter contacter=list.get(position);
        holder.linkman_name.setText(contacter.getName());
        PassengerType passengerType = PassengerType.getPassengerType(contacter.getType());
        holder.linkman_type.setText(passengerType.desc);
        holder.linkman_idcard_number.setText(contacter.getCardNo());

        return convertView;
    }
    class ViewHolder{
        TextView linkman_name;
        TextView linkman_type;
        TextView linkman_idcard_number;
    }
}
